Page({

  /**
   * 页面的初始数据
   */
  data: {
    wechat: [
      { id: "1", name: "微信", checked: 'checked' },
      { id: "2", name: '手机' },
    ],
    manandgril: [
      { id: "1", name: "男士", checked: 'checked' },
      { id: "2", name: '女士' },
    ],
    cooperation_mode: [
      { id: "1", name: "广告合作", checked: 'checked' },
      { id: "2", name: '其他合作' },
    ],
    cooperation:1,
    sex:1,
    tel:1,
  },
  // 合作方式
  cooperation:function(e){
    var id = e.detail.value;
    var pos = this.data.cooperation_mode;
    for (var index in pos) {
      if (pos[index].id == id) {
        pos[index].checked = 'checked';
      } else {
        pos[index].checked = '';
      }
    }
    this.setData({
      cooperation_mode: pos,
      cooperation: id,
    })
  },
  manandgrilchoose: function (e) {
    //男女选择
    var id = e.detail.value;
    var pos = this.data.manandgril;
    for (var index in pos) {
      if (pos[index].id == id) {
        pos[index].checked = 'checked';
      } else {
        pos[index].checked = '';
      }
    }
    this.setData({
      manandgril: pos,
      sex:id,
    })
  },
  wechatchoose: function (e) {
    //联系方式选择
    var id = e.detail.value;
    var pos = this.data.wechat;
    console.log(id);
    for (var index in pos) {
      if (pos[index].id == id) {
        pos[index].checked = 'checked';
      } else {
        pos[index].checked = '';
      }
    }
    this.setData({
      wechat: pos,
      tel:id,
    })
  },
  locationlw: function () {
    wx.navigateBack({
    })
    // wx.navigateTo({
    //   url: '../Contact/Contact'
    // })
  },
  locationdesc: function () {
    wx.navigateTo({
      url: '../Description/Description'
    })
  },
  /**
   * 表单提交
   */
  formSubmit: function (e) {
    var e = e.detail.value;
    var tel = this.data.tel;
    var sex = this.data.sex;
    var cooperation = this.data.cooperation;
    console.log(e);
    wx.request({
      url: getApp().AppUrl + '/index.php/api/set/saveCooperation',
      data: {
        name: e.name,
        gname:e.gname,
        content:e.content,
        tel:e.tels,
        ts: tel,
        sex: sex,
        mode: cooperation,
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        // 返回成功
        wx.showToast({
          title: '提交成功',
          icon: 'succes',
          duration: 2000,
          mask: true,
        })
        setTimeout(function () {
          wx.navigateBack({})
        }, 2000)
      },
      fail: function (res) {
        // 返回失败
        console.log(res.data)
      },
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})